package com.itheima.thread;

/**
 * @author wz
 * @company 公司
 * @create 2020-03-05 10:13
 */
public class Demo2CreateThread {
    public static void main(String[] args) {

        Demo2 demo2 = new Demo2();
        Thread t1 = new Thread(demo2);
        Thread t2 = new Thread(demo2);
        //设置t1,t2为守护线程
//        t1.setDaemon(true);
//        t2.setDaemon(true);

        System.out.println("子线程开始执行了");
        t1.start();
        t2.start();
        System.out.println("主线程结束了");
    }
    static class Demo2 implements Runnable{

        public void run() {
            String name = Thread.currentThread().getName();
            for (int i = 0; i < 5; i++) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(name+"内容是"+i);
            }
        }
    }
}
